home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_08 / phillip2 / cips.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-21  |  36.1 KB  |  978 lines

  1.  
  2.    /***********************************************
  3.    *
  4.    *       file d:\cips\cips.c
  5.    *
  6.    *       Functions: This file contains
  7.    *          main
  8.    *          show_menu
  9.    *          show_image
  10.    *
  11.    *       Purpose:
  12.    *          This file contains the main calling
  13.    *          routine in the C Image Processing System.
  14.    *
  15.    *       External Calls:
  16.    *          numcvrt.c - get_integer
  17.    *          gin.c - get_image_name
  18.    *          rtiff.c - read_tiff_image
  19.    *          tiff.c - read_tiff_header
  20.    *          display.c - display_image
  21.    *                      display_menu_for_display_image
  22.    *          pi.c - print_image
  23.    *          ht.c - display_using_halftoning
  24.    *                 get_threshold_value
  25.    *          djet.c - print_graphics_image
  26.    *                   get_graphics_caption
  27.    *          hist.c - display_menu_for_histogram
  28.    *                   calculate_area_histogram
  29.    *                   print_histogram
  30.    *                   show_histogram
  31.    *          edge.c - detect_edges
  32.    *                   get_edge_options
  33.    *                   quick_edge
  34.    *          edge2.c - homogeneity
  35.    *                    difference_edge
  36.    *                    contrast_edge
  37.    *                    range
  38.    *                    variance
  39.    *          edge3.c - gaussian_edge
  40.    *                    enhance_edges
  41.    *          filter.c - filter_image
  42.    *                     median_filter
  43.    *                     high_pixel
  44.    *                     low_pixel
  45.    *                     get_filter_options
  46.    *          addsub.c - add_image_array
  47.    *                     subtract_image_array
  48.    *          cutp.c - cut_image_piece
  49.    *                   paste_image_piece
  50.    *                   check_cut_and_paste_limits
  51.    *          rotate.c - rotate_flip_image_array
  52.    *          scale.c - zoom_image_array
  53.    *          segment.c - get_segmentation_options
  54.    *                      get_threshold_options
  55.    *                      manual_threshold_segmentation
  56.    *                      peak_threshold_segmentation
  57.    *                      valley_threshold_segmentation
  58.    *                      adaptive_threshold_segmentation
  59.    *          boole.c - and_image
  60.    *                    or_image
  61.    *                    xor_image
  62.    *                    nand_image
  63.    *                    nor_image
  64.    *                    not_image
  65.    *          overlay.c - non_zero_overlay
  66.    *                      zero_overlay
  67.    *                      greater_overlay
  68.    *                      less_overlay
  69.    *                      average_overlay
  70.    *          ed.c - erosion
  71.    *                 dilation
  72.    *                 mask_erosion
  73.    *                 mask_dilation
  74.    *                 interior_outline
  75.    *                 exterior_outline
  76.    *                 copy_3_x_3
  77.    *                 opening
  78.    *                 closing
  79.    *                 get_shape_options
  80.    *          morph.c - thinning
  81.    *                    dilate_not_join
  82.    *                    special_opening
  83.    *                    special_closing
  84.    *                    edm
  85.    *                    mat
  86.    *          txtrsubs.c - sigma
  87.    *                       skewness
  88.    *                       amean
  89.    *                       adifference
  90.    *                       hurst
  91.    *                       compare
  92.    *                       get_texture_options
  93.    *          geosubs.c - geometry
  94.    *                      arotate
  95.    *                      get_geometry_options
  96.    *
  97.    *       Modifications:
  98.    *          26 June 1990 - created
  99.    *
  100.    *************************************************/
  101.  
  102. #include "cips.h"
  103.  
  104.  
  105. short the_image[ROWS][COLS];
  106. short out_image[ROWS][COLS];
  107.  
  108. main()
  109. {
  110.  
  111.    char caption[80],
  112.         color_transform[80],
  113.         dir_name[80],
  114.         er_method[80],
  115.         low_high[80],
  116.         method[80],
  117.         monitor_type[80],
  118.         name[80],
  119.         name2[80],
  120.         name3[80],
  121.         rep[80],
  122.         title[80],
  123.         ts_method[80],
  124.         zoom_shrink[80];
  125.  
  126.    float angle     = 45.0,
  127.          percent   = 0.5,
  128.          x_cross   = 0.01,
  129.          x_stretch = 1.0,
  130.          y_cross   = 0.01,
  131.          y_stretch = 1.0;
  132.  
  133.    int  bilinear             = 1,
  134.         color                = 99,
  135.         detect_threshold     = 1,
  136.         detect_type          = 1,
  137.         display_colors       = 16,
  138.         element              = 1,
  139.         filter_type          = 1,
  140.         high                 = 100,
  141.         horizontal           = 3,
  142.         i                    = 0,
  143.         ie                   = 1,
  144.         ie2                  = 1,
  145.         ie3                  = 1,
  146.         il                   = 1,
  147.         il2                  = 1,
  148.         il3                  = 1,
  149.         image_colors         = 256,
  150.         invert               = 0,
  151.         j                    = 0,
  152.         l                    = 0,
  153.         length               = 3,
  154.         le                   = COLS+1,
  155.         le2                  = COLS+1,
  156.         le3                  = COLS+1,
  157.         line                 = 1,
  158.         ll                   = ROWS+1,
  159.         ll2                  = ROWS+1,
  160.         ll3                  = ROWS+1,
  161.         m                    = COLS/2,
  162.         n                    = ROWS/2,
  163.         not_finished         = 1,
  164.         number               = 1,
  165.         print                = 0,
  166.         response             = 99,
  167.         rotation_type        = 1,
  168.         scale                = 2,
  169.         show_hist            = 0,
  170.         size                 = 7,
  171.         threshold            = 128,
  172.         vertical             = 3,
  173.         width                = 3;
  174.  
  175.    long     mean_of_pixels;
  176.  
  177.    unsigned long histogram[256];
  178.  
  179.    short    diff        = 10,
  180.             erode       = 3,
  181.             hi          = 255,
  182.             low         = 0,
  183.             min_area    = 10,
  184.             max_area    = 1000,
  185.             value       = 200,
  186.             x_displace  = 10,
  187.             y_displace  = 10,
  188.             low_hi_filter[3][3];
  189.  
  190.    struct   tiff_header_struct image_header;
  191.  
  192.  
  193.    my_clear_text_screen();
  194.  
  195.    strcpy(color_transform, "Straight mode");
  196.    strcpy(monitor_type, "VGA");
  197.    strcpy(low_high, "l");
  198.    strcpy(zoom_shrink, "z");
  199.    strcpy(method, "r");
  200.    strcpy(title, "");
  201.    strcpy(ts_method, "manual");
  202.    strcpy(er_method, "edge");
  203.  
  204.    strcpy(name,  "c:/pix/adam256.tif");
  205.    strcpy(name2, "c:/pix/output.tif");
  206.    strcpy(name3, "c:/pix/output.tif");
  207.    strcpy(dir_name, "c:/pix");
  208.  
  209.      while(not_finished){
  210.  
  211.         show_menu();
  212.  
  213.         get_integer(&response);
  214.  
  215.         switch (response){
  216.  
  217.         case 1:/* display image header */
  218.          get_image_name(name);
  219.          read_tiff_header(name, &image_header);
  220.          printf("\n\nCIPS> The image header is:");
  221.          printf("\n\t\twidth=%ld length=%ld  start=%ld  bits=%ld",
  222.               image_header.image_width,
  223.               image_header.image_length,
  224.               image_header.strip_offset,
  225.               image_header.bits_per_pixel);
  226.          printf("\nCIPS> Hit Enter to continue");
  227.          gets(rep);
  228.         break;
  229.  
  230.         case 2:/* display image numbers */
  231.          get_image_name(name);
  232.          get_parameters(&il, &ie, &ll, &le);
  233.          read_tiff_image(name, the_image, il, ie, ll, le);
  234.          show_image(the_image, il, ie);
  235.          break;
  236.  
  237.         case 3:   /* print image numbers */
  238.          get_image_name(name);
  239.          get_parameters(&il, &ie, &ll, &le);
  240.          read_tiff_image(name, the_image, il, ie, ll, le);
  241.          print_image(the_image, name, 1, 1, 1, 100, 18,
  242.                      il, ie);
  243.         break;
  244.  
  245.         case 4:   /* display image */
  246.          get_image_name(name);
  247.          read_tiff_header(name, &image_header);
  248.          get_parameters(&il, &ie, &ll, &le);
  249.          display_menu_for_display_image(&image_colors,
  250.                    &display_colors, &invert,
  251.                    color_transform, monitor_type,
  252.                    &show_hist);
  253.          printf("\nEnter title>");
  254.          gets(title);
  255.          display_image(name, the_image, il, ie,
  256.                    ll, le, &image_header, monitor_type,
  257.                    color_transform, invert,
  258.                    image_colors, display_colors,
  259.                    show_hist, title);
  260.         break;
  261.  
  262.         case 5:   /* display image using halftoning */
  263.          get_image_name(name);
  264.          read_tiff_header(name, &image_header);
  265.          get_parameters(&il, &ie, &ll, &le);
  266.          display_menu_for_display_image(&image_colors,
  267.                    &display_colors, &invert,
  268.                    color_transform, monitor_type,
  269.                    &show_hist);
  270.          get_threshold_value(&threshold, &print);
  271.          display_using_halftoning(the_image, name,
  272.                    il, ie, ll, le, threshold,
  273.                    invert, image_colors, &image_header,
  274.                    monitor_type, print, show_hist,
  275.                    color_transform);
  276.         break;
  277.  
  278.         case 6:   /* print graphics image */
  279.          get_image_name(name);
  280.          read_tiff_header(name, &image_header);
  281.          get_parameters(&il, &ie, &ll, &le);
  282.          display_menu_for_display_image(&image_colors,
  283.                    &display_colors, &invert,
  284.                    color_transform, monitor_type,
  285.                    &show_hist);
  286.          get_graphics_caption(caption);
  287.          print_graphics_image(the_image, out_image,
  288.                    name, il, ie, ll, le, image_colors,
  289.                    invert, caption, show_hist,
  290.                    color_transform);
  291.         break;
  292.         case 7:   /* print or display histogram numbers */
  293.          get_image_name(name);
  294.          read_tiff_header(name, &image_header);
  295.          get_parameters(&il, &ie, &ll, &le);
  296.          display_menu_for_histogram(&print, &vertical,
  297.                    &horizontal);
  298.          calculate_area_histogram(histogram, vertical,
  299.                    horizontal, the_image, name,
  300.                    il, ie, ll, le);
  301.          if(print == 0)
  302.             show_histogram(histogram);
  303.          if(print == 1)
  304.             print_histogram(histogram, name);
  305.         break;
  306.  
  307.         case 8:  /* perform edge detection */
  308.          printf("\nCIPS> Enter input image name\n");
  309.          get_image_name(name);
  310.          printf("\nCIPS> Enter output image name\n");
  311.          get_image_name(name2);
  312.          get_parameters(&il, &ie, &ll, &le);
  313.          get_edge_options(&detect_type,
  314.                           &detect_threshold,
  315.                           &high, &size);
  316.          if(detect_type == 1  ||
  317.             detect_type == 2  ||
  318.             detect_type == 3)
  319.             detect_edges(name, name2, the_image,
  320.                          out_image, il, ie, ll, le,
  321.                          detect_type, detect_threshold,
  322.                          high);
  323.          if(detect_type == 4)
  324.             quick_edge(name, name2, the_image, out_image,
  325.                        il, ie, ll, le, detect_threshold,
  326.                        high);
  327.          if(detect_type == 5)
  328.               homogeneity(name, name2, the_image, out_image,
  329.                        il, ie, ll, le, detect_threshold,
  330.                        high);
  331.          if(detect_type == 6)
  332.               difference_edge(name, name2, the_image,
  333.                               out_image, il, ie, ll,
  334.                               le, detect_threshold,
  335.                               high);
  336.          if(detect_type == 7)
  337.               contrast_edge(name, name2, the_image,
  338.                             out_image, il, ie, ll,
  339.                             le, detect_threshold,
  340.                             high);
  341.          if(detect_type == 8)
  342.               gaussian_edge(name, name2, the_image,
  343.                             out_image, il, ie, ll,
  344.                             le, size,
  345.                             detect_threshold, high);
  346.          if(detect_type == 10)
  347.               range(name, name2, the_image, out_image,
  348.                     il, ie, ll, le, size,
  349.                     detect_threshold, high);
  350.          if(detect_type == 11)
  351.               variance(name, name2, the_image,
  352.                        out_image, il, ie, ll, le,
  353.                        detect_threshold, high);
  354.          break;
  355.  
  356.         case 9: /* perform edge enhancement */
  357.          printf("\nCIPS> Enter input image name\n");
  358.          get_image_name(name);
  359.          printf("\nCIPS> Enter output image name\n");
  360.          get_image_name(name2);
  361.          get_parameters(&il, &ie, &ll, &le);
  362.          printf("\nCIPS> Enter high threshold parameter");
  363.          printf(" \n\t___\b\b\b");
  364.          get_integer(&high);
  365.          enhance_edges(name, name2, the_image,
  366.                        out_image, il, ie, ll, le,
  367.                        high);
  368.          break;
  369.  
  370.         case 10: /* perform image filtering */
  371.          printf("\nCIPS> Enter input image name\n");
  372.          get_image_name(name);
  373.          printf("\nCIPS> Enter output image name\n");
  374.          get_image_name(name2);
  375.          get_parameters(&il, &ie, &ll, &le);
  376.          get_filter_options(&filter_type, low_high);
  377.          if(low_high[0] == 'l' ||
  378.              low_high[0] == 'L' ||
  379.              low_high[0] == 'h' ||
  380.              low_high[0] == 'H'){
  381.             setup_filters(filter_type, low_high,
  382.                           low_hi_filter);
  383.             filter_image(name, name2, the_image,
  384.                          out_image, il, ie, ll, le,
  385.                          low_hi_filter, filter_type);
  386.          }
  387.  
  388.          if(low_high[0] == 'm' ||
  389.              low_high[0] == 'M')
  390.                median_filter(name, name2, the_image,
  391.                              out_image, il, ie, ll,
  392.                              le, filter_type);
  393.  
  394.          if(low_high[0] == 'i' ||
  395.              low_high[0] == 'I')
  396.                high_pixel(name, name2, the_image,
  397.                           out_image, il, ie, ll, le,
  398.                           filter_type);
  399.  
  400.          if(low_high[0] == 'o' ||
  401.              low_high[0] == 'O')
  402.                low_pixel(name, name2, the_image,
  403.                          out_image, il, ie, ll, le,
  404.                          filter_type);
  405.  
  406.         break;
  407.  
  408.         case 11: /* perform image addition and
  409.                     subtraction */
  410.          printf("\nCIPS> Image Addition:"
  411.               "\n         output = first + second"
  412.               "\n      Image Subtractions:"
  413.               "\n         output = first - second");
  414.          printf("\nCIPS> Enter first image name\n");
  415.          get_image_name(name);
  416.          printf("\nCIPS> Enter second image name\n");
  417.          get_image_name(name2);
  418.          printf("\nCIPS> Enter output image name\n");
  419.          get_image_name(name3);
  420.          printf("\nCIPS> Enter parameters for first image");
  421.          get_parameters(&il, &ie, &ll, &le);
  422.          printf("\nCIPS> Enter parameters for second image");
  423.          get_parameters(&il2, &ie2, &ll2, &le2);
  424.          printf("\nCIPS> Enter parameters for output image");
  425.          get_parameters(&il3, &ie3, &ll3, &le3);
  426.          printf("\n\nCIPS> Enter a=addition    "
  427.                 "s=subtraction\n");
  428.          printf("\nCIPS> _\b");
  429.          gets(low_high);
  430.          if(low_high[0] == 'a' || low_high[0] == 'A')
  431.             add_image_array(name, name2, name3,
  432.                 the_image, out_image,
  433.                 il, ie, ll, le,
  434.                 il2, ie2, ll2, le2,
  435.                 il3, ie3, ll3, le3);
  436.          if(low_high[0] == 's' || low_high[0] == 'S')
  437.             subtract_image_array(name, name2, name3,
  438.                 the_image, out_image,
  439.                 il, ie, ll, le,
  440.                 il2, ie2, ll2, le2,
  441.                 il3, ie3, ll3, le3);
  442.         break;
  443.  
  444.         case 12: /* image cutting and pasting */
  445.          printf("\n\nCIPS> Cut from source image and "
  446.                 "paste to destination image");
  447.          printf("\nCIPS> Enter source image name");
  448.          get_image_name(name);
  449.          get_parameters(&il, &ie, &ll, &le);
  450.          check_cut_and_paste_limits(&il, &ie, &ll, &le);
  451.          cut_image_piece(name, the_image,
  452.                          il, ie, ll, le);
  453.          printf("\nCIPS> Enter destination image name");
  454.          get_image_name(name2);
  455.          printf("\nCIPS> Enter destination image "
  456.                 "parameters");
  457.          get_parameters(&il, &ie, &ll, &le);
  458.          check_cut_and_paste_limits(&il, &ie, &ll, &le);
  459.          paste_image_piece(name2, name, the_image,
  460.                            out_image, il, ie, ll, le);
  461.         break;
  462.  
  463.         case 13: /* image rotation and flipping */
  464.          printf("\nCIPS> Enter source image name");
  465.          get_image_name(name);
  466.          get_parameters(&il, &ie, &ll, &le);
  467.          printf("\nCIPS> Enter destination image name");
  468.          printf("\nCIPS> (source can equal destination)");
  469.          get_image_name(name2);
  470.          printf("\nCIPS> Enter destination image "
  471.                 "parameters");
  472.          get_parameters(&il2, &ie2, &ll2, &le2);
  473.          printf("\nCIPS> Enter number of Rotations "
  474.                 "(1, 2, 3)");
  475.          printf("\nCIPS> or type of Flip "
  476.                 "(4=horizontal 5=vertical)");
  477.          printf("\nCIPS> __\b");
  478.          get_integer(&rotation_type);
  479.          rotate_flip_image_array(name, name2,
  480.                                  the_image,
  481.                                  out_image, il, ie,
  482.                                  ll, le, il2, ie2,
  483.                                  ll2, le2,
  484.                                  rotation_type);
  485.         break;
  486.  
  487.         case 14: /* image scaling */
  488.          printf("\nCIPS> Enter input image name");
  489.          get_image_name(name);
  490.          get_parameters(&il, &ie, &ll, &le);
  491.          printf("\nCIPS> Enter output image name");
  492.          get_image_name(name2);
  493.          get_scaling_options(zoom_shrink, &scale, method);
  494.          if(zoom_shrink[0] == 'z' || zoom_shrink[0] == 'Z')
  495.             zoom_image_array(name, name2, the_image,
  496.                              out_image, il, ie, ll,
  497.                              le, scale, method);
  498.          if(zoom_shrink[0] == 's' ||
  499.             zoom_shrink[0] == 'S'){
  500.              printf("\nCIPS> Enter output image "
  501.                      "parameters");
  502.                get_parameters(&il2, &ie2, &ll2, &le2);
  503.              shrink_image_array(name, name2, the_image,
  504.                                 out_image, il, ie, ll,
  505.                                 le, il2, ie2, ll2, le2,
  506.                                 scale, method);
  507.          }
  508.         break;
  509.  
  510.         case 15: /* create image */
  511.          printf("\nCIPS> Enter input name of image "
  512.                 "to create");
  513.          get_image_name(name);
  514.          printf("\nCIPS> Enter number of %d blocks "
  515.                 "wide",COLS);
  516.          printf("\n      ___\b\b");
  517.          get_integer(&width);
  518.          printf("\nCIPS> Enter number of %d blocks "
  519.                 "tall",ROWS);
  520.          printf("\n      ___\b\b");
  521.          get_integer(&length);
  522.          image_header.lsb            = 1;
  523.          image_header.bits_per_pixel = 8;
  524.          image_header.image_length   = length*COLS;
  525.          image_header.image_width    = width*ROWS;
  526.          image_header.strip_offset   = 1000;
  527.          for(i=0; i<ROWS; i++)
  528.             for(j=0; j<COLS; j++)
  529.                the_image[i][j] = 0;
  530.          create_allocate_tiff_file(name, &image_header,
  531.                                    the_image);
  532.         break;
  533.  
  534.         case 16: /* image thresholding */
  535.          printf("\nCIPS> Enter input image name\n");
  536.          get_image_name(name);
  537.          printf("\nCIPS> Enter output image name\n");
  538.          get_image_name(name2);
  539.          get_parameters(&il, &ie, &ll, &le);
  540.          get_threshold_options(ts_method, &hi,
  541.                                &low, &value);
  542.          if(ts_method[0] == 'm' ||
  543.             ts_method[0] == 'M')
  544.             manual_threshold_segmentation(name,
  545.                    name2, the_image, out_image,
  546.                    il, ie, ll, le,
  547.                    hi, low, value, 0);
  548.          if(ts_method[0] == 'p' ||
  549.             ts_method[0] == 'P')
  550.             peak_threshold_segmentation(name,
  551.                    name2, the_image, out_image,
  552.                    il, ie, ll, le, value, 0);
  553.          if(ts_method[0] == 'v' ||
  554.             ts_method[0] == 'V')
  555.             valley_threshold_segmentation(name,
  556.                    name2, the_image, out_image,
  557.                    il, ie, ll, le, value, 0);
  558.          if(ts_method[0] == 'a' ||
  559.             ts_method[0] == 'a')
  560.             adaptive_threshold_segmentation(name,
  561.                    name2, the_image, out_image,
  562.                    il, ie, ll, le, value, 0);
  563.         break;
  564.  
  565.         case 17: /* image segmentation */
  566.          printf("\nCIPS> Enter input image name\n");
  567.          get_image_name(name);
  568.          printf("\nCIPS> Enter output image name\n");
  569.          get_image_name(name2);
  570.          get_parameters(&il, &ie, &ll, &le);
  571.          get_segmentation_options(ts_method, &hi,
  572.                                   &low, &value);
  573.          if(ts_method[0] == 'm' ||
  574.             ts_method[0] == 'M')
  575.             manual_threshold_segmentation(name,
  576.                    name2, the_image, out_image,
  577.                    il, ie, ll, le,
  578.                    hi, low, value, 1);
  579.          if(ts_method[0] == 'p' ||
  580.             ts_method[0] == 'P')
  581.             peak_threshold_segmentation(name,
  582.                    name2, the_image, out_image,
  583.                    il, ie, ll, le, value, 1);
  584.          if(ts_method[0] == 'v' ||
  585.             ts_method[0] == 'V')
  586.             valley_threshold_segmentation(name,
  587.                    name2, the_image, out_image,
  588.                    il, ie, ll, le, value, 1);
  589.          if(ts_method[0] == 'a' ||
  590.             ts_method[0] == 'a')
  591.             adaptive_threshold_segmentation(name,
  592.                    name2, the_image, out_image,
  593.                    il, ie, ll, le, value, 1);
  594.         break;
  595.  
  596.         case 18: /* edge & gray shade segmentation */
  597.          printf("\nCIPS> Enter input image name\n");
  598.          get_image_name(name);
  599.          printf("\nCIPS> Enter output image name\n");
  600.          get_image_name(name2);
  601.          get_parameters(&il, &ie, &ll, &le);
  602.          get_edge_region_options(er_method,
  603.              &detect_type, &min_area, &max_area,
  604.              &value, &diff, &percent, &erode);
  605.          if(er_method[0] == 'e' ||
  606.             er_method[0] == 'E')
  607.             edge_region(name, name2, the_image,
  608.                         out_image, il, ie, ll, le,
  609.                         detect_type, min_area,
  610.                         max_area, diff, percent,
  611.                         value, erode);
  612.          if(er_method[0] == 'g' ||
  613.             er_method[0] == 'G')
  614.             gray_shade_region(name, name2, the_image,
  615.                         out_image, il, ie, ll, le,
  616.                         diff, min_area, max_area);
  617.          if(er_method[0] == 'c' ||
  618.             er_method[0] == 'C')
  619.             edge_gray_shade_region(name, name2,
  620.                         the_image, out_image,
  621.                         il, ie, ll, le, detect_type,
  622.                         min_area, max_area, diff,
  623.                         percent, value, erode);
  624.         break;
  625.  
  626.         case 19: /* Boolean operations */
  627.          printf("\nCIPS> Boolean operations:"
  628.                 "\n      output = first OP second"
  629.                 "\n      If using NOT operation, "
  630.                 "\n      only enter one set of"
  631.                 "\n      parameters.");
  632.          printf("\nCIPS> Enter first image name\n");
  633.          get_image_name(name);
  634.          printf("\nCIPS> Enter second image name\n");
  635.          get_image_name(name2);
  636.          printf("\nCIPS> Enter output image name\n");
  637.          get_image_name(name3);
  638.          printf("\nCIPS> Enter parameters for first image");
  639.          get_parameters(&il, &ie, &ll, &le);
  640.          printf("\nCIPS> Enter parameters for second image");
  641.          get_parameters(&il2, &ie2, &ll2, &le2);
  642.          printf("\nCIPS> Enter parameters for output image");
  643.          get_parameters(&il3, &ie3, &ll3, &le3);
  644.          printf("\n\nCIPS> Enter operation: and or xor nand nor"
  645.                 " not\n");
  646.          gets(low_high);
  647.  
  648.          if(strncmp("and", low_high, 3) == 0){
  649.             and_image(name, name2, name3,
  650.                       the_image, out_image,
  651.                       il,  ie,  ll,  le,
  652.                       il2, ie2, ll2, le2,
  653.                       il3, ie3, ll3, le3);
  654.          }
  655.          if(strncmp("or", low_high, 2) == 0){
  656.             or_image(name, name2, name3,
  657.                      the_image, out_image,
  658.                      il,  ie,  ll,  le,
  659.                      il2, ie2, ll2, le2,
  660.                      il3, ie3, ll3, le3);
  661.          }
  662.          if(strncmp("xor", low_high, 3) == 0){
  663.             xor_image(name, name2, name3,
  664.                       the_image, out_image,
  665.                       il,  ie,  ll,  le,
  666.                       il2, ie2, ll2, le2,
  667.                       il3, ie3, ll3, le3);
  668.          }
  669.          if(strncmp("nand", low_high, 4) == 0){
  670.             printf("\nEnter the value of ON pixel");
  671.             printf("\n\t___\b\b\b");
  672.             get_short(&value);
  673.             nand_image(name, name2, name3,
  674.                        the_image, out_image,
  675.                        il,  ie,  ll,  le,
  676.                        il2, ie2, ll2, le2,
  677.                        il3, ie3, ll3, le3, value);
  678.          }
  679.          if(strncmp("nor", low_high, 3) == 0){
  680.             printf("\nEnter the value of ON pixel");
  681.             printf("\n\t___\b\b\b");
  682.             get_short(&value);
  683.             nor_image(name, name2, name3,
  684.                       the_image, out_image,
  685.                       il,  ie,  ll,  le,
  686.                       il2, ie2, ll2, le2,
  687.                       il3, ie3, ll3, le3, value);
  688.          }
  689.          if(strncmp("not", low_high, 3) == 0){
  690.             printf("\nEnter the value of ON pixel");
  691.             printf("\n\t___\b\b\b");
  692.             get_short(&value);
  693.             not_image(name, name2, name3,
  694.                       the_image, out_image,
  695.                       il,  ie,  ll,  le, value);
  696.          }
  697.         break;
  698.  
  699.         case 20: /* overlay operations */
  700.          printf("\nCIPS> Overlay operations:"
  701.                 "\n      output = first OP second");
  702.          printf("\nCIPS> Enter first image name\n");
  703.          get_image_name(name);
  704.          printf("\nCIPS> Enter second image name\n");
  705.          get_image_name(name2);
  706.          printf("\nCIPS> Enter output image name\n");
  707.          get_image_name(name3);
  708.          printf("\nCIPS> Enter parameters for first image");
  709.          get_parameters(&il, &ie, &ll, &le);
  710.          printf("\nCIPS> Enter parameters for second image");
  711.          get_parameters(&il2, &ie2, &ll2, &le2);
  712.          printf("\nCIPS> Enter parameters for output image");
  713.          get_parameters(&il3, &ie3, &ll3, &le3);
  714.          printf("\n\nCIPS> Enter: non-zero zero "
  715.                 "greater less average\n");
  716.          gets(low_high);
  717.  
  718.          if(strncmp("non", low_high, 3) == 0){
  719.             non_zero_overlay(name, name2, name3,
  720.                              the_image, out_image,
  721.                              il,  ie,  ll,  le,
  722.                              il2, ie2, ll2, le2,
  723.                              il3, ie3, ll3, le3);
  724.          }
  725.          if(strncmp("zero", low_high, 4) == 0){
  726.             zero_overlay(name, name2, name3,
  727.                          the_image, out_image,
  728.                          il,  ie,  ll,  le,
  729.                          il2, ie2, ll2, le2,
  730.                          il3, ie3, ll3, le3);
  731.          }
  732.          if(strncmp("gre", low_high, 3) == 0){
  733.             greater_overlay(name, name2, name3,
  734.                             the_image, out_image,
  735.                              il,  ie,  ll,  le,
  736.                              il2, ie2, ll2, le2,
  737.                             il3, ie3, ll3, le3);
  738.          }
  739.          if(strncmp("less", low_high, 4) == 0){
  740.             less_overlay(name, name2, name3,
  741.                          the_image, out_image,
  742.                          il,  ie,  ll,  le,
  743.                          il2, ie2, ll2, le2,
  744.                          il3, ie3, ll3, le3);
  745.          }
  746.          if(strncmp("ave", low_high, 3) == 0){
  747.             average_overlay(name, name2, name3,
  748.                              the_image, out_image,
  749.                             il,  ie,  ll,  le,
  750.                             il2, ie2, ll2, le2,
  751.                             il3, ie3, ll3, le3);
  752.          }
  753.         break;
  754.  
  755.         case 21: /* shape operations */
  756.          printf("\nCIPS> Enter input image name\n");
  757.          get_image_name(name);
  758.          printf("\nCIPS> Enter output image name\n");
  759.          get_image_name(name2);
  760.          get_parameters(&il, &ie, &ll, &le);
  761.          get_shape_options(low_high, &value,
  762.                            &threshold, &number);
  763.          if(strncmp("thi", low_high, 3) == 0){
  764.             thinning(name, name2, the_image, out_image,
  765.                      il, ie, ll, le,
  766.                      value, threshold, 0);
  767.          }
  768.          if(strncmp("dnj", low_high, 3) == 0){
  769.             dilate_not_join(name, name2, the_image,
  770.                             out_image, il, ie, ll, le,
  771.                             value, threshold);
  772.          }
  773.          if(strncmp("ero", low_high, 3) == 0){
  774.             erosion(name, name2, the_image, out_image,
  775.                     il, ie, ll, le, value, threshold);
  776.          }
  777.          if(strncmp("dil", low_high, 3) == 0){
  778.             dilation(name, name2, the_image, out_image,
  779.                      il, ie, ll, le, value, threshold);
  780.          }
  781.          if(strncmp("mer", low_high, 3) == 0){
  782.             mask_erosion(name, name2, the_image,
  783.                          out_image, il, ie, ll, le,
  784.                          value, threshold);
  785.          }
  786.          if(strncmp("mdi", low_high, 3) == 0){
  787.             mask_dilation(name, name2, the_image,
  788.                           out_image, il, ie, ll, le,
  789.                           value, threshold);
  790.          }
  791.          if(strncmp("int", low_high, 3) == 0){
  792.             interior_outline(name, name2, the_image,
  793.                              out_image, il, ie, ll, le,
  794.                              value, threshold);
  795.          }
  796.          if(strncmp("ext", low_high, 3) == 0){
  797.             exterior_outline(name, name2, the_image,
  798.                              out_image, il, ie, ll, le,
  799.                              value, threshold);
  800.          }
  801.          if(strncmp("ope", low_high, 3) == 0){
  802.             opening(name, name2, the_image, out_image,
  803.                     il, ie, ll, le, value, threshold,
  804.                     number);
  805.          }
  806.          if(strncmp("clo", low_high, 3) == 0){
  807.             closing(name, name2, the_image, out_image,
  808.                     il, ie, ll, le, value, threshold,
  809.                     number);
  810.          }
  811.          if(strncmp("spo", low_high, 3) == 0){
  812.             special_opening(name, name2, the_image,
  813.                             out_image, il, ie, ll, le,
  814.                             value, threshold,
  815.                             number);
  816.          }
  817.          if(strncmp("spc", low_high, 3) == 0){
  818.             special_closing(name, name2, the_image,
  819.                             out_image, il, ie, ll, le,
  820.                             value, threshold,
  821.                             number);
  822.          }
  823.          if(strncmp("edm", low_high, 3) == 0){
  824.             edm(name, name2, the_image, out_image,
  825.                 il, ie, ll, le, value);
  826.          }
  827.          if(strncmp("mat", low_high, 3) == 0){
  828.             edm(name, name2, the_image, out_image,
  829.                 il, ie, ll, le, value);
  830.          }
  831.         break;
  832.  
  833.         case 22: /* texture operations */
  834.          printf("\nCIPS> Enter input image name\n");
  835.          get_image_name(name);
  836.          printf("\nCIPS> Enter output image name\n");
  837.          get_image_name(name2);
  838.          get_parameters(&il, &ie, &ll, &le);
  839.          get_texture_options(low_high, &threshold,
  840.                              &value, &size,
  841.                              &line, &element);
  842.          if(strncmp(low_high, "compare", 3) == 0)
  843.             compare(name, name2, the_image, out_image,
  844.                     il, ie, ll, le,
  845.                     line, element, size);
  846.          if(strncmp(low_high, "hurst", 3) == 0)
  847.             hurst(name, name2, the_image, out_image,
  848.                   il, ie, ll, le, size);
  849.          if(strncmp(low_high, "adifference", 3) == 0)
  850.             adifference(name, name2, the_image,
  851.                         out_image, il+i*ROWS,
  852.                         ie, ll, le, size);
  853.          if(strncmp(low_high, "amean", 3) == 0)
  854.             amean(name, name2, the_image, out_image,
  855.                   il, ie, ll, le, size);
  856.          if(strncmp(low_high, "skewness", 3) == 0)
  857.             skewness(name, name2, the_image, out_image,
  858.                      il, ie, ll, le, size, 
  859.                      threshold, value);
  860.          if(strncmp(low_high, "sigma", 3) == 0)
  861.             sigma(name, name2, the_image, out_image,
  862.                   il, ie, ll, le, size, 
  863.                   threshold, value);
  864.  
  865.         break;
  866.  
  867.         case 23:  /* geometry operations */
  868.          printf("\nCIPS> Enter input image name\n");
  869.          get_image_name(name);
  870.          printf("\nCIPS> Enter output image name\n");
  871.          get_image_name(name2);
  872.          get_parameters(&il, &ie, &ll, &le);
  873.          get_geometry_options(
  874.                      method, &angle, 
  875.                      &x_displace, &y_displace, 
  876.                      &x_stretch, &y_stretch, 
  877.                      &x_cross,  &y_cross, 
  878.                      &bilinear, &m, &n);
  879.          if(strncmp(method, "geometry", 3) == 0)
  880.             geometry(name, name2, 
  881.                   the_image, out_image,
  882.                   il, ie, ll, le, angle, 
  883.                   x_stretch, y_stretch,
  884.                   x_displace, y_displace,
  885.                   x_cross, y_cross,
  886.                   bilinear);
  887.          if(strncmp(method, "rotate", 3) == 0)
  888.             arotate(name, name2, 
  889.                   the_image, out_image,
  890.                   il, ie, ll, le,
  891.                   angle, m, n, bilinear);
  892.         break;
  893.  
  894.         case 30:  /* exit system */
  895.          not_finished = 0;
  896.         break;
  897.  
  898.         default:
  899.          printf("\nCould not understand response, "
  900.                 "try again");
  901.         break;
  902.  
  903.      }               /* ends switch response */
  904.   }               /* ends while not finished */
  905. }               /* ends main                 */
  906.  
  907.  
  908.  
  909.  
  910.  
  911.  
  912.    /*************************************************
  913.    *
  914.    *   show_image(...
  915.    *
  916.    *   This function displays the image numbers on the
  917.    *   screen as text.  It displays 20 rows  with 18
  918.    *   columns each.
  919.    *
  920.    **************************************************/
  921.  
  922. show_image(image, il, ie)
  923.    int   il, ie;
  924.    short image[ROWS][COLS];
  925. {
  926.    int i, j;
  927.    printf("\n   ");
  928.    for(i=0; i<18; i++)
  929.       printf("-%3d", i+ie);
  930.  
  931.    for(i=0; i<20; i++){
  932.       printf("\n%2d>", i+il);
  933.       for(j=0; j<18; j++)
  934.          printf("-%3d", image[i][j]);
  935.    }
  936.  
  937.    printf("\nPress enter to continue");
  938.    get_integer(&i);
  939.  
  940. }  /* ends show_image  */
  941.  
  942.  
  943.  
  944.  
  945.  
  946.    /*************************************************
  947.    *
  948.    *   show_menu(..
  949.    *
  950.    *   This function displays the CIPS main menu.
  951.    *
  952.    **************************************************/
  953.  
  954. show_menu()
  955. {
  956.  
  957.  printf(""
  958.  "\n\n\t\t\tWelcome to CIPS"
  959.  "\n\t\tThe C Image Processing System"
  960.  "\n\t\tDwayne Phillips 1990-1993"
  961.  "\nThese are your choices:"
  962.  "\n1.  Display image header               13. Image rotate & flip" 
  963.  "\n2.  Show image numbers                 14. Image scaling"    
  964.  "\n3.  Print image numbers                15. Create blank image" 
  965.  "\n4.  Display (EGA & VGA)                16. Image thresholding"
  966.  "\n5.  Display or print using halftoning  17. Image segmentation"
  967.  "\n6.  Print using dithering              18. Edge & gray segmentation"
  968.  "\n7.  Print or display histogram         19. Boolean operations"
  969.  "\n8.  Edge Detection                     20. Image overlay"
  970.  "\n9.  Edge Enhancement                   21. Shape operations"  
  971.  "\n10. Image filtering                    22. Texture operations"
  972.  "\n11. Image add & subtract               23. Geometry operations" 
  973.  "\n12 Image cut & paste                   "
  974.  "\n30. Exit system\n"
  975.  "\nEnter choice __\b\b");
  976.  
  977. }  /* ends show_menu */
  978.